package com.zfzs.post.controller;

import com.zfzs.post.aop.log.Log;
import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.model.dto.OrderDTO;
import com.zfzs.post.model.vo.OrderListVO;
import com.zfzs.post.model.vo.OrderVO;
import com.zfzs.post.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wq
 * @date 2019/10/22 13:57
 * @description
 */
@RestController
@RequestMapping("order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询个人订单列表
     * @param params
     * @return
     */
    @PostMapping("get_order_list")
    @Log("查询个人订单列表")
    public ResponseResult getOrderList(@RequestBody Map<String,Object> params){
        List<OrderListVO> list=orderService.getOrderList(params);
        return ResponseResult.ok(new HashMap<String,List<OrderListVO>>(){{put("list",list);}});
    }

    /**
     * 根据id查询订单
     * @param params
     * @return
     */
    @PostMapping("get_order_byId")
    @Log("根据id查询订单")
    public ResponseResult getOrderById(@RequestBody Map<String,Object> params){
        OrderVO v=orderService.getOrderById(params);
        return ResponseResult.ok(v);
    }

    /**
     * 添加订单
     * @param orderDTO
     * @return
     */
    @PostMapping("add_order")
    @Log("添加订单")
    public ResponseResult addOrder(@RequestBody OrderDTO orderDTO){
        String orderNo=orderService.addOrder(orderDTO);
        return ResponseResult.ok(new HashMap<String,String>(){{put("orderNo",orderNo);}});
    }

    /**
     * 删除订单
     * @param params
     * @return
     */
    @PostMapping("delete_order")
    @Log("删除订单")
    public ResponseResult deleteOrder(@RequestBody Map<String,String> params){
        orderService.deleteOrder(params);
        return ResponseResult.ok();
    }

    /**
     * 确认收货
     * @param params
     * @return
     */
    @PostMapping("confirm_order")
    @Log("确认收货")
    public ResponseResult confirmOrder(@RequestBody Map<String,String> params){
        orderService.confirmOrder(params);
        return ResponseResult.ok();
    }

    /**
     * 取消订单
     * @param params
     * @return
     */
    @PostMapping("cancel_order")
    @Log("取消订单")
    public ResponseResult cancelOrder(@RequestBody Map<String,String> params){
        orderService.cancelOrder(params);
        return ResponseResult.ok();
    }


}
